package ua.gov.diia.ui_base.components.atom.icon

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import ua.gov.diia.ui_base.R
import ua.gov.diia.ui_base.components.infrastructure.event.UIAction
import ua.gov.diia.ui_base.components.infrastructure.event.UIActionKeysCompose
import ua.gov.diia.ui_base.components.theme.Black
import ua.gov.diia.ui_base.components.theme.White

@Composable
fun IconBiometricAtm(
    modifier: Modifier = Modifier,
    onUIAction: (UIAction) -> Unit
) {
    val interactionSource = remember { MutableInteractionSource() }
    val isPressed by interactionSource.collectIsPressedAsState()

    Box(
        modifier = modifier
            .clip(CircleShape)
            .background(
                color = if (isPressed) Black else Color.Transparent,
                shape = CircleShape
            )
            .padding(12.dp)
            .clickable(
                interactionSource = interactionSource,
                indication = null,
                onClick = {
                    onUIAction(UIAction(UIActionKeysCompose.TOUCH_ID_BUTTON))
                }
            ),
        contentAlignment = Alignment.Center
    ) {
        Icon(
            painter = painterResource(id = R.drawable.ic_touch_id_large),
            contentDescription = stringResource(id = R.string.accessibility_num_tile_biometric_button),
            tint = if (isPressed) White else Black
        )
    }
}

@Preview
@Composable
fun IconBiometricAtmPreview() {
    IconBiometricAtm {
        /* no-op */
    }
}